import {
  tokenHolder
} from '../../config/apiServe/new-rpc'
import {
  getTokenMsgArr
} from '../../config/apiServe/fetch-config'
export default {
  data() {
    return {
      baseCoin: require(`../../assets/img/coin${process.env.VUE_APP_BASECOIN_URL}`),
      symbol: process.env.VUE_APP_BASECOIN,
      holders: 0,
      param: [
        [{
          "match": [{
            "value": process.env.VUE_APP_BASECOIN,
            "key": "asset_symbol"
          }],
          "range": [{
            "key": "balance",
            "gt": 0
          }]
        }]
      ],
      info: {}
    };
  },
  mounted() {
    this.getCoinsHolders()
    this.getCoinsInfo()
    this.getCoinsTime()
  },
  methods: {
    async getCoinsHolders() {
      const res = await tokenHolder(this.param)
      this.holders = res.result[0] || 0
    },
    async getCoinsInfo() {
      const res = await getTokenMsgArr([this.symbol], process.env.VUE_APP_PLATFORM || '')
      this.$set(this.info, 'introduce', res.data[0].introduce)
    },
    async getCoinsTime() {
      const res = await this.Rpc.getHeaders(1, 1)
      this.$set(this.info, 'time', res.result.items[0].blockTime)
    },
    introFilter(item, lang = this.$store.state.initLang) {
      let language = lang
      switch (lang) {
        case 'zh':
          language = 'zh-CN'
          break
        case 'ja':
          break
        case 'en':
          language = 'en-US'
          break
        default:
          break;
      }
      return item.introduce && JSON.parse(item.introduce)[language] !== "" ?
        JSON.parse(item.introduce)[language] :
        item.introduction;
    },
  }
};